#include "chartdialog.h"
#include "ui_chartdialog.h"



ChartDialog::ChartDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ChartDialog)
{
    ui->setupUi(this);

    WellOrgData= new WellData;
    InitSimData();
    // 构建图表对象
    QChart* chart = new QChart();
    // 构建折线系列对象
    QLineSeries *series_00 = new QLineSeries();
    QLineSeries *series_01 = new QLineSeries();
    for (quint32 i = 0; i < DATA_RAM_HALF; i++)
    {
    //调用append()接口，传递的参数x、y对用的是一组坐标数据。
    series_00->append(i, WellOrgData->LoadV[i]);
    series_01->append(i, WellOrgData->AccV[i]);
    }
    //设置曲线颜色
    QColor MyColor("#00FF00");
    QColor MyColor01("#FF0000");
    series_00->setColor(MyColor);
    series_01->setColor(MyColor01);
    //设置曲线名称
    series_00->setName("载荷");
    series_01->setName("加速度");
    //
    float X_min,X_max;

    chart->setTitle("载荷加速度对比曲线");
    //chart->setMinimumHeight()
    // 将系列添加到图表
    chart->addSeries(series_00);
    chart->addSeries(series_01);


    // 基于已添加到图表的 series 来创建默认的坐标轴
    //chart->createDefaultAxes();

    //创建坐标
    QValueAxis *axisX = new QValueAxis;//X轴
    axisX->setRange(0, 420);//设置坐标轴范围
    axisX->setTitleText("time(10ms)");//标题
    axisX->setLabelFormat("%.1f"); //标签格式：每个单位保留几位小数
    axisX->setTickCount(1); //主分隔个数：0到10分成20个单位
    axisX->setMinorTickCount(4); //每个单位之间绘制了多少虚网线
    //    axisX->setGridLineVisible(false);

    QValueAxis *axisY = new QValueAxis; //Y 轴
    axisY->setRange(-2, 2);
    axisY->setTitleText("value");
    axisY->setLabelFormat("%.2f"); //标签格式
    axisY->setTickCount(4);
    axisY->setMinorTickCount(4);
    //    axisX->setGridLineVisible(false);

    //为序列设置坐标轴
    //chart->setAxisX(axisX, series_00);
    //chart->setAxisY(axisY, series_00);

    //chart->setAxisX(axisX, series_01);
    //chart->setAxisY(axisY, series_01);

    chart->addAxis ( axisX, Qt::AlignBottom );
    chart->addAxis ( axisY, Qt::AlignLeft );
    series_00->attachAxis ( axisX );
    series_00->attachAxis ( axisY );
    series_01->attachAxis ( axisX );
    series_01->attachAxis ( axisY );

    // 将图表绑定到视图
   // ui->widget->setChart(chart);
    ui->widget_4->setChart(chart);
}

ChartDialog::~ChartDialog()
{
    delete ui;
}

void ChartDialog::InitSimData()
{
    for (int i=0;i<DATA_RAM_HALF;i++)
    {
        WellOrgData->LoadV[i]=0.74609375;
        WellOrgData->AccV[i]=1.0;
    }
}
